<template>
  <div class="booking-item" @click="handleItemClick">
    <!-- 预约日期时间 -->
    <div class="booking-time">
      <el-icon class="time-icon">
        <Clock />
      </el-icon>
      <span class="time-text">{{ booking.createTime }}</span>
    </div>
    
    <!-- 房源信息卡片 -->
    <div class="room-card">
      <!-- 房源图片 -->
      <div class="room-image">
        <img :src="booking.img" :alt="booking.title" />
        <!-- 房源标签 -->
        <div class="room-tags" v-if="booking.tags && booking.tags.length">
          <span 
            v-for="tag in booking.tags.slice(0, 2)" 
            :key="tag.name"
            class="room-tag"
          >
            {{ tag.name }}
          </span>
        </div>
      </div>
      
      <!-- 房源详情 -->
      <div class="room-info">
        <!-- 房源标题 -->
        <h4 class="room-title">{{ booking.title }}</h4>
        
        <!-- 房源子标题 -->
        <p class="room-subtitle">{{ booking.subTitle }}</p>
        
        <!-- 距离信息 -->
        <div class="distance-info" v-if="booking.distanceInfo">
          <el-icon class="location-icon">
            <Location />
          </el-icon>
          <span class="distance-text">{{ booking.distanceInfo }}</span>
        </div>
        
        <!-- 租金信息 -->
        <div class="price-info">
          <span class="price">{{ booking.rentPrice }}元/月</span>
        </div>
      </div>
    </div>
    
    <!-- 操作按钮 -->
    <div class="booking-actions">
      <el-button 
        type="danger" 
        plain 
        size="small"
        @click.stop="handleCancel"
      >
        取消预约
      </el-button>
      <el-button 
        type="primary" 
        size="small"
        @click.stop="handleContact"
      >
        去咨询
      </el-button>
    </div>
  </div>
</template>

<script setup>
import { Clock, Location } from '@element-plus/icons-vue'

const props = defineProps({
  booking: {
    type: Object,
    required: true
  }
})

const emit = defineEmits(['click', 'cancel', 'contact'])

const handleItemClick = () => {
  emit('click', props.booking)
}

const handleCancel = () => {
  emit('cancel', props.booking.id)
}

const handleContact = () => {
  emit('contact', props.booking)
}
</script>

<style scoped>
.booking-item {
  background-color: #fff;
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid #f0f0f0;
}

.booking-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  border-color: #e0e0e0;
}

.booking-time {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background-color: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
}

.time-icon {
  font-size: 14px;
  color: #409eff;
  margin-right: 6px;
}

.time-text {
  font-size: 13px;
  color: #666;
  line-height: 1.2;
}

.room-card {
  display: flex;
  padding: 16px;
}

.room-image {
  position: relative;
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  margin-right: 12px;
  border-radius: 8px;
  overflow: hidden;
}

.room-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.booking-item:hover .room-image img {
  transform: scale(1.05);
}

.room-tags {
  position: absolute;
  top: 4px;
  left: 4px;
  display: flex;
  gap: 2px;
}

.room-tag {
  background-color: rgba(64, 158, 255, 0.9);
  color: #fff;
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 3px;
  backdrop-filter: blur(4px);
}

.room-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.room-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin: 0 0 6px 0;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-subtitle {
  font-size: 13px;
  color: #666;
  margin: 0 0 6px 0;
  line-height: 1.2;
}

.distance-info {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.location-icon {
  font-size: 12px;
  color: #999;
  margin-right: 4px;
}

.distance-text {
  font-size: 12px;
  color: #666;
  line-height: 1.2;
}

.price-info {
  display: flex;
  align-items: center;
}

.price {
  font-size: 16px;
  font-weight: 600;
  color: #e74c3c;
}

.booking-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background-color: #fafafa;
  border-top: 1px solid #f0f0f0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .room-card {
    padding: 12px;
  }
  
  .room-image {
    width: 70px;
    height: 70px;
    margin-right: 10px;
  }
  
  .room-title {
    font-size: 14px;
  }
  
  .room-subtitle {
    font-size: 12px;
  }
  
  .distance-text {
    font-size: 11px;
  }
  
  .price {
    font-size: 14px;
  }
  
  .booking-actions {
    padding: 10px 12px;
  }
  
  .booking-time {
    padding: 10px 12px;
  }
  
  .time-text {
    font-size: 12px;
  }
  
  .room-tag {
    font-size: 8px;
    padding: 1px 3px;
  }
}

/* 动画效果 */
@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.booking-item {
  animation: slideInUp 0.4s ease;
}

/* 状态指示器样式 */
.booking-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, #409eff 0%, #67c23a 100%);
  border-radius: 0 2px 2px 0;
}

/* 按钮悬停效果优化 */
.booking-actions .el-button {
  transition: all 0.3s ease;
}

.booking-actions .el-button:hover {
  transform: translateY(-1px);
}
</style>
